package nowCoder;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;


public class PrintFromTopToBottom {
	
	class TreeNode{
		int val;
		TreeNode left,right;
		public TreeNode(int val) {
			this.val = val;
		}
	}
	
	public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
		Queue<TreeNode> queue = new LinkedList<TreeNode>();
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		queue.add(root);
		while(!queue.isEmpty()){
			TreeNode popNode = queue.poll();
			list.add(popNode.val);
			if(popNode.left!=null)
				queue.add(popNode.left);
			if(popNode.right!=null)
				queue.add(popNode.right);
		}
		return list;
	}
	
	}
